home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FishMarket 1.0
/
FishMarket v1.0.iso
/
fishies
/
201-225
/
disk_222
/
plplot
/
src
/
source.zoo
/
plcntr.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-05-15
|
6KB
|
207 lines
/* Contour "ny" by "nx" real array "points" at the level "zlev" */
/* points is a pointer to a 2d array of nx by ny points. */
/* iscan has nx elements. ixstor and iystor each have nstor elements. */
#include "plplot.h"
void plcntr(points,nx,ny,kx,lx,ky,ly,zlev,iscan,ixstor,iystor,nstor,tr)
int nx, ny, ky, ly, kx, lx, nstor;
float zlev, *points;
int iscan[], ixstor[], iystor[];
void (*tr)();
{
int kcol, krow, kstor, kscan, iwbeg, ixbeg, iybeg, izbeg;
int iboun, iw, ix, iy, iz, ifirst, istep, ixgo, iygo;
int l, ixg, iyg, ia, ib, ixt, iyt, jstor, next;
float dist, dx, dy, xnew, ynew, x, y;
float xlas=0., ylas=0., tpx, tpy, xt, yt;
/* Initialize memory pointers */
kstor = 0;
kscan = 0;
for (krow=ky; krow<=ly; krow++) {
for (kcol=kx+1; kcol <= lx; kcol++) {
/* Check if a contour has been crossed */
x = *(points + (kcol-2)*ny + krow-1);
y = *(points + (kcol-1)*ny + krow-1);
if (x < zlev && y >= zlev) {
ixbeg = kcol-1;
iwbeg = kcol;
}
else if (y < zlev && x >= zlev) {
ixbeg = kcol;
iwbeg = kcol-1;
}
else
goto lab70;
iybeg = krow;
izbeg = krow;
/* Yes, a contour has been crossed. Check to see if it */
/* is a new one. */
for(l=0;l<kscan;l++)
if (ixbeg == iscan[l]) goto lab70;
/* Here is the section which follows and draws a contour */
for (iboun=1; iboun>= -1; iboun -= 2) {
/* Set up starting point and initial search directions */
ix = ixbeg;
iy = iybeg;
iw = iwbeg;
iz = izbeg;
ifirst = 1;
istep = 0;
ixgo = iw - ix;
iygo = iz - iy;
lab20:
plccal(points,nx,ny,zlev,ix,iy,ixgo,iygo,&dist);
dx = dist * ixgo;
dy = dist * iygo;
xnew = ix+dx;
ynew = iy+dy;
/* Has a step occured in search? */
if (istep != 0) {
if (ixgo*iygo == 0) {
/* This was a diagonal step, so interpolate missed */
/* point, rotating 45 degrees to get it */
ixg = ixgo;
iyg = iygo;
plr45(&ixg,&iyg,iboun);
ia = iw-ixg;
ib = iz-iyg;
plccal(points,nx,ny,zlev,ia,ib,ixg,iyg,&dist);
(*tr)(xlas,ylas,&tpx,&tpy);
drawor(tpx,tpy);
dx = dist*ixg;
dy = dist*iyg;
xlas = ia+dx;
ylas = ib+dy;
}
else {
if (dist > 0.5) {
xt = xlas;
xlas = xnew;
xnew = xt;
yt = ylas;
ylas = ynew;
ynew = yt;
}
}
}
if (ifirst != 1) {
(*tr)(xlas,ylas,&tpx,&tpy);
drawor(tpx,tpy);
}
else {
(*tr)(xnew,ynew,&tpx,&tpy);
movwor(tpx,tpy);
}
xlas = xnew;
ylas = ynew;
/* Check if the contour is closed */
if (ifirst != 1 && ix == ixbeg && iy == iybeg
&& iw == iwbeg && iz == izbeg) {
(*tr)(xlas,ylas,&tpx,&tpy);
drawor(tpx,tpy);
goto lab70;
}
ifirst = 0;
/* Now the rotation */
istep = 0;
plr45(&ixgo,&iygo,iboun);
iw = ix+ixgo;
iz = iy+iygo;
/* Check if out of bounds */
if (iw<kx || iw>lx || iz<ky || iz>ly) goto lab50;
/* Has contact been lost with the contour? */
if (*(points+(iw-1)*ny+iz-1) < zlev) {
/* Yes, lost contact => step to new centre */
istep = 1;
ix = iw;
iy = iz;
plr135(&ixgo,&iygo,iboun);
iw = ix+ixgo;
iz = iy+iygo;
/* And do the contour memory */
if (iy == krow) {
kscan = kscan+1;
iscan[kscan-1] = ix;
}
else if (iy>krow) {
kstor = kstor+1;
if (kstor>nstor) {
fatal("Heap exhausted in PLCONT.");
goto lab70;
}
ixstor[kstor-1] = ix;
iystor[kstor-1] = iy;
}
}
goto lab20;
lab50:
/* Reach here only if boundary encountered - Draw last bit */
(*tr)(xnew,ynew,&tpx,&tpy);
drawor(tpx,tpy);
}
lab70:
; /* Null statement to carry label */
}
/* Search of row complete - set up memory of next row in iscan and */
/* edit ixstor and iystor */
if (krow<ny) {
jstor = 0;
kscan = 0;
next = krow+1;
for (l=1; l<=kstor; l++) {
ixt = ixstor[l-1];
iyt = iystor[l-1];
/* Memory of next row into iscan */
if (iyt == next) {
kscan = kscan+1;
iscan[kscan-1] = ixt;
/* Retain memory of rows to come, and forget rest */
}
else if (iyt>next) {
jstor = jstor+1;
ixstor[jstor-1] = ixt;
iystor[jstor-1] = iyt;
}
}
kstor = jstor;
}
}
}